package net.gyapp.markim.module.basic.base;

import android.content.Context;
import android.graphics.Paint;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseViewHolder;
import com.easyder.wrapper.core.manager.ImageManager;

import me.winds.widget.autolayout.utils.AutoUtils;


/**
 * Author:  winds
 * Data:    2017/5/9
 * Desc:    通用BaseViewHolder
 */

public class BaseRecyclerHolder extends BaseViewHolder {
    public BaseRecyclerHolder(View view) {
        super(view);
        AutoUtils.auto(view);
    }

    /**
     * 显示带删除线字体
     *
     * @param viewId
     * @param text
     */
    public BaseRecyclerHolder setDeleteText(int viewId, CharSequence text) {
        TextView view = getView(viewId);
        view.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG | Paint.ANTI_ALIAS_FLAG);//删除线
        view.setText(text);
        return this;
    }

    /**
     * 将文本域设置可见再显示文字
     *
     * @param viewId
     * @param msg
     * @return
     */
    public BaseRecyclerHolder setVisibleText(int viewId, CharSequence msg) {
        TextView view = getView(viewId);
        view.setVisibility(View.VISIBLE);
        view.setText(msg);
        return this;
    }

    /**
     * 加载指定URL的图片并设置到targetView
     *
     * @param context
     * @param viewId
     * @param url
     */
    public void setImageManager(Context context, int viewId, String url) {
        ImageManager.load(context, (ImageView) getView(viewId), url, -1);
    }

    /**
     * 加载图片
     *
     * @param context
     * @param viewId
     * @param url
     * @param placeholder
     */
    public void setImageManager(Context context, int viewId, String url, int placeholder) {
        ImageManager.load(context, (ImageView) getView(viewId), url, placeholder);
    }

    public void setImageManager(Context context, ImageView imageView, String url, int placeholder) {
        ImageManager.load(context, imageView, url, placeholder);
    }


    /**
     * 加载图片
     *
     * @param context
     * @param viewId
     * @param url
     * @param placeholder 值为 -1 / 0 表示不加载
     * @param error       值为 -1 / 0 表示不加载
     */
    public void setImageManager(Context context, int viewId, String url, int placeholder, int error) {
        ImageManager.load(context, (ImageView) getView(viewId), url, null, placeholder, error);
    }


    public BaseViewHolder setClickListener(int viewId, View.OnClickListener listener) {
        View view = getView(viewId);
        view.setOnClickListener(listener);
        return this;
    }


}
